<?php

if (!defined("EXPONENT")) exit("");
if (!isset($_REQUEST['ajax_action']) || ($_REQUEST['ajax_action'] != 1))
  exponent_flow_redirect();
$gallery = null;
if (isset($_GET['id'])) $gallery = $db->selectObject("imagegallery_gallery","id=".intval($_GET['id']));

if ($gallery) {
	$loc = unserialize($gallery->location_data);
	
	$images = $db->selectObjects("imagegallery_image","gallery_id=".$gallery->id . ' ORDER BY rank DESC ');
	// ok, build xml slideshow for flex app
	$xml='<tiltviewergallery><photos>';
	for ($i = 0; $i < count($images); $i++) {
		$file = $db->selectObject("file","id=".$images[$i]->file_id);
		// build xml
		$xml.="<photo imageurl='".URL_BASE."/{$file->directory}/{$file->filename}'>
    <title>{$images[$i]->name}</title><description>{$images[$i]->alt}</description>
    </photo>";
	}
	$xml.="	</photos></tiltviewergallery>";
	// save xml into temp
	$fp=fopen("tmp/playlist/". $gallery->id.".xml","w");
	fwrite($fp,$xml);
	fclose($fp);
	//chmod(BASE."tmp/playlist/". $gallery->id.".xml",777);
	// ok, next
	//$template = new template("imagegallerymodule","_view_gallery",$iloc);
	$template = new template("imagegallerymodule","_slideshow");
	//eDebug($gallery); exit();
	$template->assign("gallery",$gallery);
	ob_start();
  $template->output();
  $xml=ob_get_contents();
  ob_clean();
  echo $xml;
  die();
} else {
	echo SITE_404_HTML;
}

?>
